package cn.school.classManage.service.impl;

import cn.school.common.utils.SysUserUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.school.classManage.entity.ClassCurriculumUser;
import cn.school.classManage.service.ClassCurriculumUserService;
import cn.school.classManage.dao.ClassCurriculumUserMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 *
 */
@Service
public class ClassCurriculumUserServiceImpl extends ServiceImpl<ClassCurriculumUserMapper, ClassCurriculumUser>
    implements ClassCurriculumUserService{

    @Resource
    ClassCurriculumUserMapper curriculumUserMapper;


    @Override
    public int addAllCurriculumUser(List<ClassCurriculumUser> curriculumUser) {
        String userId = String.valueOf(SysUserUtils.getSysUser().getId());
        int num=0;
        List<ClassCurriculumUser> list=curriculumUserMapper.getDetailListByMainID(userId,null);
        if(list.size()>0){
            for (ClassCurriculumUser classCurriculumUser : curriculumUser) {
                classCurriculumUser.setCreateBy(userId);
                num = curriculumUserMapper.updateCurriculumUser(classCurriculumUser);
            }
        }else {
        for (ClassCurriculumUser classCurriculumUser : curriculumUser) {
            classCurriculumUser.setCreateBy(userId);
            classCurriculumUser.setCreateTime(new Date());
            num = curriculumUserMapper.insert(classCurriculumUser);
        }
        }
        return num;
    }


    @Override
    public List<ClassCurriculumUser> getUserList(ClassCurriculumUser user) {
        //获取用户名
        user.setCreateBy(String.valueOf(SysUserUtils.getSysUser().getId()));
        List<ClassCurriculumUser> detailListByMainID = curriculumUserMapper.getDetailListByMainID(user.getCreateBy(),user.getCreateTime());
        return detailListByMainID;
    }

}




